package com.yc.web.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yc.api.HostInfo;
import com.yc.web.PO.HostInfoPO;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public  interface HostInfoMapper extends BaseMapper<HostInfoPO> {

    /**
     * 获取主机唯一标识列表
     * @return 主机唯一标识列表
     */




    @Select("  SELECT \n" +
            "    host, \n" +
            "    CASE \n" +
            "        WHEN MAX(FROM_UNIXTIME(create_time / 1000)) >= NOW() - INTERVAL 5 SECOND THEN 1 \n" +
            "        ELSE 0 \n" +
            "    END AS isonline \n" +
            "FROM \n" +
            "    t_host_info \n" +
            "GROUP BY \n" +
            "    host" +
            " order by isonline desc")
    List<HostInfo> findHostInfoList();

    /**
     * 根据主机唯一标识查询主机状态信息
     * @return 主机状态信息
     */
    @Select("SELECT host, create_time AS createTime, used_memory AS usedMemory,\n" +
            "               total_memory AS totalMemory, used_cpu AS usedCpu\n" +
            "        FROM t_host_info WHERE host = #{host}\n" +
            "        ORDER BY create_time desc LIMIT 100")
    List<HostInfo> findHostInfo(String host);

}

